package com.souku.finance.application.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;

import com.souku.finance.application.R;
import com.souku.finance.application.bean.TasksBean;

import java.util.List;

/**
 * Created by Android on 2016/12/20.
 */

public class VipTaskAdapter extends BaseAdapter {

    private List<TasksBean.DataBean> list;
    private OnClick click;

    public VipTaskAdapter(List<TasksBean.DataBean> list,OnClick click) {
        this.list = list;
        this.click=click;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = convertView;
        ViewHolder viewHolder = null;
        if (view == null || !(view.getTag() instanceof ViewHolder)) {
            view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_viptask, null);
            viewHolder = new ViewHolder(view);
            view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }

        final TasksBean.DataBean bean=list.get(position);
        viewHolder.tvName.setText(bean.getTaskName());
        viewHolder.dec.setText(bean.getRecommend());
        if(bean.getIsFinish().equals("1")){
            if(bean.getIsReceived().equals("1")){
                viewHolder.btnGo.setOnClickListener(null);
            }else {
                viewHolder.btnGo.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        click.click(true,bean.getId());
                    }
                });
            }
        }else {
            viewHolder.btnGo.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    click.click(false,bean.getId());
                }
            });
        }
        return view;
    }

    static class ViewHolder {
        protected TextView tvName;
        protected TextView dec;
        protected Button btnGo;

        ViewHolder(View rootView) {
            initView(rootView);
        }

        private void initView(View rootView) {
            tvName = (TextView) rootView.findViewById(R.id.tv_name);
            dec = (TextView) rootView.findViewById(R.id.dec);
            btnGo = (Button) rootView.findViewById(R.id.btn_go);
        }
    }

    public interface OnClick{
        void click(boolean isreceive,String id);
    }
}
